/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mpinventory;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.JFrame;

/**
 *
 * @author msi
 */
public class Mpinventory {

    private static Login login;
    private static JFrame loginFrame;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Toolkit tk=Toolkit.getDefaultToolkit();
        Dimension screenSize=tk.getScreenSize();
        final int screenHeight=screenSize.height;
        final int screenWidth=screenSize.width;
        final Driver d=new Driver();
        loginFrame=new JFrame("Log-in");
        login=new Login(d.connector.getConnector(),screenWidth,screenHeight);
        loginFrame.add(login);
        loginFrame.setSize(login.getWidth(), login.getHeight());
        loginFrame.setLocation((screenWidth-login.getWidth())/2,(screenHeight-login.getHeight())/2);
        loginFrame.setVisible(true);
        loginFrame.setResizable(false);
        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ActionListener actionListener=new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent actionEvent){
                if(login.isSuccessful())
                    loginFrame.dispose();
                try{
                    if(login.mainMenu.backToLogin){
                        loginFrame=new JFrame("Log-in");
                        login=new Login(d.connector.getConnector(),screenWidth,screenHeight);
                        loginFrame.add(login);
                        loginFrame.setSize(login.getWidth(), login.getHeight());
                        loginFrame.setLocation((screenWidth-login.getWidth())/2,(screenHeight-login.getHeight())/2);
                        loginFrame.setVisible(true);
                        loginFrame.setResizable(false);
                        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        login.mainMenu.backToLogin=false;
                    }
                }catch(Exception e){}
            }
        };
        Timer timer=new Timer(0, actionListener);
        timer.start();
    }
}
